﻿Imports System.Collections.Generic
Imports System.Linq
Imports System.Text

Namespace Config
    Public Class ErrorInfo
        Private m_ExManagerConfig As ExceptionConfig
        Private DEFAULT_MESSAGE As String = ""

        Public Sub New(ByVal config As ExceptionConfig)
            m_ExManagerConfig = config
        End Sub

        Public Function GetErrorInfoById(ByVal strErrorCode As String) As String
            Dim strResult As String
            If m_ExManagerConfig.ErrorCodeSource = ErrorCodeSource.DB Then
                strResult = GetErrorInfoFormDatabase(strErrorCode)
            Else
                strResult = GetErorrInfoFromXml(strErrorCode)
            End If
            Return strResult
        End Function

        Private Function GetErrorInfoFormDatabase(ByVal strErrorCode As String) As String
            Return "test error message"
        End Function

        Private Function GetErorrInfoFromXml(ByVal strErrorCode As String) As String
            Dim xmlDoc As New System.Xml.XmlDocument()
            xmlDoc.Load(m_ExManagerConfig.ConnectionString)
            Dim xmlNodeList As System.Xml.XmlNodeList = xmlDoc.SelectNodes("ErrorInfo")
            For Each node As System.Xml.XmlNode In xmlNodeList
                If node.Attributes("Code").Value = strErrorCode.ToString() Then
                    Return node.Attributes("String").Value
                End If
            Next
            Return DEFAULT_MESSAGE
        End Function
    End Class
End Namespace
